using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Bornander.UI.ListItems
{
    public partial class FormulaOneTeam : UserControl, IExtendedListItem
    {
        private bool onOddRow = false;
        private bool isSelected = false;

        public FormulaOneTeam()
        {
            InitializeComponent();
        }

        public FormulaOneTeam(Image carPicture, Image firstDriverPicture, Image secondDriverPicture, string teamName, string firstDriverName, string secondDriverName)
        {
            InitializeComponent();

            this.carPicture.Image = carPicture;
            this.firstDriver.Image = firstDriverPicture;
            this.secondDriver.Image = secondDriverPicture;
            this.teamName.Text = teamName;
            this.firstDriverName.Text = firstDriverName;
            this.secondDriverName.Text = secondDriverName;

            SetSelectedState(false);
        }

        private void SetSelectedState(bool isSelected)
        {
            carPicture.Visible = !isSelected;
            teamName.Visible = !isSelected;

            firstDriver.Visible = isSelected;
            secondDriver.Visible = isSelected;
            firstDriverName.Visible = isSelected;
            secondDriverName.Visible = isSelected;
        }

        private void SetBackColor()
        {
            if (isSelected)
                BackColor = onOddRow ? Color.AliceBlue : Color.LightBlue;
            else
                BackColor = onOddRow ? Color.White : Color.Silver;
        }

        #region IExtendedListItem Members

        public void SelectedChanged(bool isSelected)
        {
            this.isSelected = isSelected;
            SetSelectedState(isSelected);

            SetBackColor();
        }

        public void PositionChanged(int index)
        {
            onOddRow = (index & 1) == 0;
            SetBackColor();
        }

        #endregion

        #region Public properties

        public string TeamName
        {
            get { return teamName.Text; }
        }

        public string FirstDriver
        {
            get { return firstDriverName.Text; }
        }

        public string SecondDriver
        {
            get { return secondDriverName.Text; }
        }

        #endregion
    }
}
